package com.taotao.st3.controller.enums;

import com.taotao.st3.base.RespData;
import com.taotao.st3.base.enumhub.CodeTextEnumView;
import com.taotao.st3.base.enumhub.EnumHub;
import com.taotao.st3.enums.HobyEnum;
import com.taotao.st3.enums.PersonDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.List;

import static org.springframework.web.bind.annotation.RequestMethod.GET;


/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author saytime
 * @since 2018-12-06
 */
@Tag(name = "枚举演示")
@RestController
@RequestMapping("/")
public class EnumController {


    @Operation(summary = "查询枚举下拉框", description = "")
    @RequestMapping(value = "/emumList", method = GET)
    public List<CodeTextEnumView> emumList(@Parameter(description = "枚举ID") @RequestParam(value = "enumId") String enumId) {

        return EnumHub.getCodeTextEnumViewList(enumId);
    }


    @Operation(summary = "枚举名称显示", description = "")
    @RequestMapping(value = "/enumName", method = GET)
    public RespData<PersonDTO> enumName() {
        PersonDTO p = new PersonDTO();
        p.setAge(30);
        p.setName("mikesrytryeruututututtu");
        p.setBirthday(LocalDateTime.now());
        p.setHoby(HobyEnum.basketball.getCode());

        return RespData.successResp(p);
    }

    @Operation(summary = "枚举扩展名称显示", description = "")
    @RequestMapping(value = "/mask", method = GET)
    public RespData<PersonDTO> mask() {
        PersonDTO p = new PersonDTO();
        p.setAge(30);
        p.setName("mikesrytryeruututututtu");
        p.setBirthday(LocalDateTime.now());
        p.setHoby("chess");

        return RespData.successResp(p);
    }


    @Operation(summary = "枚举校验", description = "")
    @RequestMapping(value = "/enumValid", method = RequestMethod.POST)
    public RespData<PersonDTO> enumValid(@Valid @RequestBody PersonDTO p) {

        return RespData.successResp(p);
    }


    @Operation(summary = "枚举校验2", description = "")
    @RequestMapping(value = "/enumValid2", method = RequestMethod.POST)
    public String enumValid2(@Valid @ModelAttribute PersonDTO p) {

        return "";
    }


    @Operation(summary = "header参数", description = "")
    @RequestMapping(value = "/header", method = GET)
    public RespData<PersonDTO> header(@Parameter(description = "编码") @RequestHeader(value = "code") String code) {


        PersonDTO p = new PersonDTO();
        p.setAge(30);
        p.setName("mikesrytryeruututututtu");
        p.setBirthday(LocalDateTime.now());
        p.setHoby(HobyEnum.basketball.getCode());

        return RespData.successResp(p);
    }


    @Operation(summary = "path参数", description = "")
    @RequestMapping(value = "/path/{code}", method = GET)
    public RespData<PersonDTO> pathVal(@Parameter(description = "编码") @PathVariable(value = "code") String code) {


        PersonDTO p = new PersonDTO();
        p.setAge(30);
        p.setName("mikesrytryeruututututtu");
        p.setBirthday(LocalDateTime.now());
        p.setHoby(HobyEnum.basketball.getCode());

        return RespData.successResp(p);
    }
}
